package cn.com.ksplatform.modules.system.dyload.controller;

import java.net.MalformedURLException;
import java.net.URL;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.ksplatform.base.SimpleReturn;
import cn.com.ksplatform.modules.system.dyload.service.IDyLoadService;

@Controller
@RequestMapping("/modules/system/dyload")
public class DyLoadController {
	
	private IDyLoadService dyLoadService;
	
	
	public IDyLoadService getDyLoadService() {
		return dyLoadService;
	}
	@Autowired
	@Qualifier("system.modules.system.DyLoadService")
	public void setDyLoadService(IDyLoadService dyLoadService) {
		this.dyLoadService = dyLoadService;
	}

	/**
	 * 加载配置
	 * @return
	 */
	@RequestMapping("loadConfig")
	@ResponseBody
	public Object loadConfig(String xml){
		return SimpleReturn.success("动态加载成功");
	}
	
	/**
	 * 加载class 或  jar 
	 * @return
	 * @throws Exception 
	 * @throws MalformedURLException 
	 */
	@RequestMapping("loadBinary")
	@ResponseBody
	public Object loadBinary(@RequestParam(value="url") String url) throws MalformedURLException, Exception{
		System.out.println(32321321);
		return SimpleReturn.success("动态加载成功");
	}
	
	
	/**
	 * 加载模块 
	 * @return
	 * @throws Exception 
	 * @throws MalformedURLException 
	 */
	@RequestMapping("loadModule")
	@ResponseBody
	public Object loadModule(@RequestParam(value="url") String url) throws MalformedURLException, Exception{
		dyLoadService.loadSpringModule(new URL(url));
		return SimpleReturn.success("动态加载成功");
	}
}
